package com.tarena.vehicle.management.controller;

import com.tarena.vehicle.common.pojo.vo.PageData;
import com.tarena.vehicle.common.web.JsonResult;
import com.tarena.vehicle.management.pojo.param.VehicleInspectionAddNewParam;
import com.tarena.vehicle.management.pojo.param.VehicleInspectionUpdateParam;
import com.tarena.vehicle.management.pojo.query.VehicleInspectionQuery;
import com.tarena.vehicle.management.pojo.vo.VehicleInspectionListItemVO;
import com.tarena.vehicle.management.pojo.vo.VehicleInspectionStandardVO;
import com.tarena.vehicle.management.service.IVehicleInspectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/VehicleInspection")
@Api(tags = "车辆年检信息管理")
public class VehicleInspectionController {

    private static final Logger logger= LoggerFactory.getLogger(VehicleInspectionController.class);

    @Autowired
    private IVehicleInspectionService vehicleInspectionService;


    @ApiOperation("新增车辆年检信息")
    @PostMapping("/add-new")
    public JsonResult addNew(@Validated VehicleInspectionAddNewParam vehicleInspectionAddNewParam){
        logger.info("接收到的车辆年检信息{}",vehicleInspectionAddNewParam);
        vehicleInspectionService.addNew(vehicleInspectionAddNewParam);
        return JsonResult.ok("添加成功");
    }

    @ApiOperation("根据ID查询年检信息")
    @GetMapping("/get-vehicleInspection-byId/{id}")
    public JsonResult<VehicleInspectionStandardVO> getVehicleInspectionById(@PathVariable Integer id){
        VehicleInspectionStandardVO vo=vehicleInspectionService.getVehicleInspectionById(id);
        return JsonResult.ok(vo);
    }

    @ApiOperation("分页查询所有年检信息,可根据条件搜索")
    @GetMapping("/get-all")
    public JsonResult<PageData<VehicleInspectionListItemVO>> getVehicleInspectionList(VehicleInspectionQuery query,Integer pageNum,Integer pageSize){
        PageData<VehicleInspectionListItemVO> pageData=vehicleInspectionService.getVehicleInspectionList(query,pageNum,pageSize);
        return JsonResult.ok(pageData);
    }

    @ApiOperation("修改年检状态为通过")
    @GetMapping("/{id}/pass")
    public JsonResult setPass(@PathVariable Integer id){
        vehicleInspectionService.setPass(id);
        return JsonResult.ok("修改状态成功");
    }

    @ApiOperation("修改年检状态为未通过")
    @GetMapping("/{id}/not-pass")
    public JsonResult setNotPass(@PathVariable Integer id){
        vehicleInspectionService.setNotPass(id);
        return JsonResult.ok("修改状态成功");
    }

    @ApiOperation("修改年检信息")
    @PostMapping("update-vehicleInspection")
    public JsonResult updateVehicleInspection(VehicleInspectionUpdateParam vehicleInspectionUpdateParam){
        vehicleInspectionService.updateVehicleInspection(vehicleInspectionUpdateParam);
        return JsonResult.ok("修改信息成功");
    }
    @ApiOperation("删除年检信息")
    @GetMapping("/delete-vehicleInspection/{id}")
    public JsonResult deleteVehicleInspection(@PathVariable Integer id){
        vehicleInspectionService.deleteVehicleInspectionById(id);
        return JsonResult.ok("删除成功");
    }



}
